package cn.edu.ujn.lab3.service;

import cn.edu.ujn.lab3.dao.*;
import cn.edu.ujn.lab3.utils.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 车场Service接口实现类
 */
@Service("parkAreaService")
@Transactional
public class ParkAreaServiceImpl implements ParkAreaService {
	// 注入ParkAreaMapper
	@Autowired
	private ParkAreaMapper parkAreaMapper;


    @Override
    public Page<ParkArea> finParkAreaList(Integer page, Integer rows, String area, String position, String type, String master) {
        ParkArea parkArea = new ParkArea();
        parkArea.setArea(area);
        parkArea.setPosition(position);
        parkArea.setType(type);
        parkArea.setMaster(master);
        // 当前页
        parkArea.setStart((page-1) * rows) ;
        // 每页数
        parkArea.setRows(rows);
        // 查询记录列表
        List<ParkArea> parkAreaList =
                parkAreaMapper.selectParkAreaList(parkArea);
        Integer count = parkAreaMapper.selectParkAreaListCount(parkArea);
        // 创建Page返回对象
        Page<ParkArea> result = new Page<>();
        result.setPage(page);
        result.setRows(parkAreaList);
        result.setSize(rows);
        result.setTotal(count);
        return result;
    }

    @Override
    public List<ParkArea> selectList(ParkArea parkArea) {
        return parkAreaMapper.selectParkAreaList(parkArea);
    }

    @Override
    public int createParkArea(ParkArea parkArea) {
        return parkAreaMapper.insert(parkArea);
    }

    @Override
    public int updateParkArea(ParkArea parkArea) {
        return parkAreaMapper.updateByPrimaryKey(parkArea);
    }

    @Override
    public int deleteParkArea(Integer id) {
        return parkAreaMapper.deleteByPrimaryKey(id);
    }

    @Override
    public ParkArea getParkAreaById(Integer id) {
        return parkAreaMapper.selectByPrimaryKey(id);
    }
}
